package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.mapper.AccountInfoMapper;
import com.koron.css2.clientCenter.vo.AccountBalanceVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 * 账户余额信息
 * 
 * @author 甄玉晴 2020年6月4日
 */
public class AccountBalanceQuery implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			// 入参转换
			@SuppressWarnings("unchecked")
			Map<String, String> map = JsonUtils.objectToPojo(req.getData(), Map.class);
			if (map == null || StringUtils.isEmpty(map.get("fuzzyQuery"))) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "缺少查询条件", void.class);
			}
			AccountInfoMapper mapper = factory.getMapper(AccountInfoMapper.class);
			AccountBalanceVO bean = mapper.getAccountBalanceInfo(map.get("fuzzyQuery"));
			if (bean == null) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "账户编号不存在。", Void.class);
			}
			// 返回结果集
			MessageBean<AccountBalanceVO> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "sucess",
					AccountBalanceVO.class);
			msg.setData(bean);
			return msg;
		} catch (Exception e) {
			logger.error("根据条件查询账户余额失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", Void.class);
		}
	}

}
